﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SharpDiary.Core.ORMapping;
using SharpDiary.Core.Utility;

namespace SharpDiary.Core.Controls
{
    public partial class EmotionListItem : ListItemControlBase
    {
        private EmotionInfo _emotion;

        public EmotionInfo Emotion
        {
            get { return _emotion; }
            set
            {
                _emotion = value;
                DisplayItemInfo();
            }
        }

        public EmotionListItem()
        {
            InitializeComponent();
        }

        protected override void DisplayItemInfo()
        {
            base.DisplayItemInfo();

            if (_emotion != null)
            {
                Title = _emotion.Name;
                Description = _emotion.Description;
                Logo = Utils.BytesToImage(_emotion.Picture);
                CreatedAndUpdateDatetime = string.Empty;
            }
        }

        protected override void OnEditButtonClick(object sender, EventArgs e)
        {
            base.OnEditButtonClick(sender, e);

            UserSettings.ShellInstance.ExecuteAction("SharpDiary.Emotion", "35b41107-af01-4318-ae0e-8dbbe0cd5711", _emotion, this);
        }

        /// <summary>
        /// 删除。
        /// </summary>
        private void Remove()
        {
            if (_emotion == null) { return; }

            if (MessageBoxHelper.ShowConfirmation("您确定要删除此心情图示吗？", true) == DialogResult.Yes)
            {
                if (EmotionInfo.Remove<EmotionInfo>(_emotion)) { this.Hide(); this.Dispose(); }
            }
        }

        protected override void OnDeleteButtonClick(object sender, EventArgs e)
        {
            base.OnDeleteButtonClick(sender, e);

            Remove();
        }
    }
}
